package router

import (
	"awesomeProject/goods-web/api/goods"
	"awesomeProject/goods-web/middlewares"
	"github.com/gin-gonic/gin"
)

func InitGoodsRouter(Router *gin.RouterGroup) {
	GoodsRouter := Router.Group("goods").Use(middlewares.Trace())
	{
		// 我们前端渲染出商品列表，然后添加一个按钮，按完后就可以新增商品，所以在一个页面
		GoodsRouter.GET("", goods.List)
		GoodsRouter.POST("", middlewares.JWTAuth(), middlewares.IsAdminAuth(), goods.New) // 新增商品需要管理员权限
		GoodsRouter.GET("./:id", goods.Detail)
		GoodsRouter.DELETE("./:id", middlewares.JWTAuth(), middlewares.IsAdminAuth(), goods.Delete)
		GoodsRouter.GET("./:id/stocks", goods.Stocks) // 获取商品库存

		// 即使路径相同，但是PATCH和GET、PUT的逻辑不同，可以看成不同的请求
		GoodsRouter.PATCH("./:id", middlewares.JWTAuth(), middlewares.IsAdminAuth(), goods.UpdateStatus)
		GoodsRouter.PUT("./:id", middlewares.JWTAuth(), middlewares.IsAdminAuth(), goods.Update)
	}

}
